var supplierObj = [];
var limit = 30;var proTypeObj = convertEnumToObj(proTypeList); var todoTimer;
layui.use(['laypage', 'table', 'form', 'laydate'], function(){
    var table = layui.table,laydate = layui.laydate,util = layui.util,form = layui.form,element = layui.element;
    laydate.render({
        elem: '#search-startTime',
        type: 'datetime',
        done: function(value, date, endDate){

        }
    });
    laydate.render({
        elem: '#search-endTime',
        type: 'datetime',
        done: function(value, date, endDate){

        }
    });

    let todoCols = [
        [
            {field: 'strength', title: '强度', width:120, align: 'center',sort:true}
            ,{field: 'proStere', title: '发货量', width:120, align: 'center',totalRow:true}
            // ,{field: 'proStere', title: '发货量', width:120, align: 'center',totalRow:true}
            ,{field: 'dosage', title: '容重', width:120, align: 'center',sort:true}
            ,{field: 'SN', title: '水泥', width: 100, align: 'center',totalRow:true}
            ,{field: 'JZS', title: '机制砂', width:100, align: 'center',totalRow:true}
            ,{field: 'SZ01', title: '石子01', width:100, align: 'center',totalRow:true}
            ,{field: 'SZ12', title: '石子12', width:100, align: 'center',totalRow:true}
            ,{field: 'MH', title: '粉煤灰', width:100, align: 'center',totalRow:true}
            ,{field: 'SF', title: '石粉', width:100, align: 'center',totalRow:true}
            ,{field: 'KF', title: '矿粉', width:100, align: 'center',totalRow:true}
            ,{field: 'WJJ', title: '外加剂', width: 100, align: 'center',totalRow:true}
            ,{field: 'PZJ', title: '膨胀剂', width:100, align: 'center',totalRow:true}
            ,{field: 'ZSJ', title: '增塑剂', width:100, align: 'center',totalRow:true}
            ,{field: 'TJJ', title: '调节剂', width:100, align: 'center',totalRow:true}
            ,{field: 'HS', title: '河沙', width:100, align: 'center',totalRow:true}
            ,{field: 'PS', title: '片石', width:100, align: 'center',totalRow:true}
            ,{field: 'QT', title: '水', width:100, align: 'center',totalRow:true}
        ]
    ];

    table.render({
        elem: '#body-list'
        ,url: '/lab-expend/strength-dosage'
        ,method: 'post'
        // ,page: true
        ,cols: todoCols
        ,totalRow:true
        // ,limit: limit
        ,height:800
        // ,limits: [30,50,100]
        // ,request: {
        //     pageName: 'curr' //页码的参数名称，默认：page
        //     ,limitName: 'limit' //每页数据量的参数名，默认：limit
        // }
        ,where: {
            // offset: 0,
            // limit: limit
            startTime:$('.search-startTime').val(),
            endTime:$('.search-endTime').val()
        }
        ,parseData: function(res){ //res 即为原始返回的数据
            console.log(res)
            if (res.code == 0 && res.data != null) {
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": 0, //解析数据长度
                    "data": res.data //解析数据列表
                };
            } else {
                return {
                    "code": res.code, //解析接口状态
                    "msg": '没有任何数据', //解析提示文本
                    "count": 0, //解析数据长度
                    "data": '' //解析数据列表
                };
            }
        }
    });

    form.on('select(search-line)', function(data) {
        $(".btn-query").trigger("click");
    });
    $('.btn-export').on('click', function () {//导出报表
        var searchVal = $('.search-text').val();
        var startTime=$('.search-startTime').val();
        var endTime=$('.search-endTime').val();
        var lineId=$('.search-line').val();
        var orgId = $('.search-origin').val();
        var orgName = $('.search-origin').find("option:selected").text();
        var option = {page:1,limit:limit};
        if (!isNull(searchVal))
            option['searchVal'] = searchVal;
        if (!isNull(startTime))
            option['startTime'] = startTime;
        if (!isNull(endTime))
            option['endTime'] = endTime;
        if (!isNull(lineId))
            option['lineId'] = lineId;
        if (orgId == null) {
            orgId = -1;
            layer.msg('请选择导出公司~!');
            return;
        }
        if (isNull(startTime)) {
            layer.msg('请选择导出开始时间~!');
            return ;
        }
        if (isNull(endTime)) {
            layer.msg('请选择导出结束时间~!');
            return ;
        }
        var loading = layer.load(1);
        layer.confirm('是否导出' + startTime + ' 至 ' + endTime + '砼强度材料平均用量明细表?', {
            btn: ['确定', '取消']
        }, function(index, layero){
            exportData('/lab-expend/storage-dosage-export',{
                searchVal:searchVal,startTime:startTime,endTime:endTime,orgId:orgId,lineId:lineId,
                limit:500000, orgName:orgName,
            },function () {
                // $(".btn-query").trigger("click");
            },null,null);
            layer.closeAll();
        }, function(index){

            layer.closeAll();
        });
    });
    $('.btn-query').on('click', function () {//搜索按钮
        var searchVal = $('.search-text').val();
        var startTime=$('.search-startTime').val();
        var endTime=$('.search-endTime').val();
        var lineId=$('.search-line').val();
        var option = {page:1,limit:limit};
        if (!isNull(searchVal))
            option['searchVal'] = searchVal;
        if (!isNull(startTime))
            option['startTime'] = startTime;
        if (!isNull(endTime))
            option['endTime'] = endTime;
        if (!isNull(lineId))
            option['lineId'] = lineId;
        // console.log(option)
        table.reload('body-list', {
            where: option,page:{curr:1}
        });
    });

});